#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/1/15 17:59
@desc
"""

import re


def com11(str):
    return re.match(r'(?P<phone_no>\d{11})', str)


def com86(str):
    return re.match(r'(?P<h86>(86))(?P<phone_no>\d{11})', str)


def parser_phone_len13(ostr):
    try:
        phone_no = com86(ostr).group('phone_no')
    except:
        phone_no = ''
    return phone_no


def parser_phone_len11(ostr):
    try:
        phone_no = com11(ostr).group('phone_no')
    except:
        phone_no = ''
    return phone_no


def parser_msisdn(o_msisdn):
    if o_msisdn in ('\\N', '') or len(o_msisdn) > 13:
        return ''
    elif len(o_msisdn) == 11:
        return parser_phone_len11(o_msisdn)
    elif len(o_msisdn) == 13:
        return parser_phone_len13(o_msisdn)
    else:
        return ''


if __name__ == '__main__':
    s = '8613903514444AA'
    var = parser_msisdn(s)
    print(var)


